﻿package  {
import com.urbansquall.serenity.*;
import com.urbansquall.metronome.*;
import com.urbansquall.utils.FPS;

import flash.display.*;
import flash.text.*;
import flash.utils.*;
import flash.events.*;

public class Main extends Sprite {
	
	private var m_entityContainer: EntityContainer;
	private var m_ticker : Ticker;
	
	public function Main()
	{
		m_entityContainer = new EntityContainer();
		
		m_ticker = new Ticker( 20 );
		m_ticker.addEventListener( TickerEvent.TICK, tick );
		m_ticker.start();
		
		var fps : FPS = new FPS();
		fps.x = this.stage.stageWidth/2 - fps.width/2;
		addChild( fps );
	}
	
	private function createEntity() : void
	{
		var entity : Entity = new Entity( this );
		this.addChild( entity );
		
		m_entityContainer.addEntity( entity );
	}
	
	public function killEntity( a_entity : Entity ) : void
	{		
		removeChild( a_entity );
		m_entityContainer.removeEntity( a_entity );
	}
	
	public function tick( a_tickEvent : TickerEvent ) : void
	{
		createEntity();

		m_entityContainer.tick( a_tickEvent.interval );
	}
} // c
} // p